package com.mcc.app.carbonEmission.controller;

import java.util.Date;
import java.util.List;

import com.github.pagehelper.PageInfo;
import com.mcc.app.carbonEmission.domain.FilenameDTO;
import com.mcc.common.config.ProjectConfig;
import com.mcc.common.utils.SecurityUtils;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.mcc.common.utils.file.FileUploadUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mcc.common.annotation.Log;
import com.mcc.common.core.controller.BaseController;
import com.mcc.common.core.domain.AjaxResult;
import com.mcc.common.enums.BusinessType;
import com.mcc.app.carbonEmission.domain.ReportAssist;
import com.mcc.app.carbonEmission.service.IReportAssistService;
import com.mcc.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 辅助报表
 *
 * @author gxy
 * @date 2025-07-03
 */
@Api(tags = "辅助报表")
@RestController
@RequestMapping("/carbonEmission/assist")
public class ReportAssistController extends BaseController {

    @Autowired
    private IReportAssistService reportAssistService;

    @ApiOperation("查询辅助报表列表")
    @ApiOperationSupport(order = 1)
    @PreAuthorize("@ss.hasPermi('carbonEmission:assist:list')")
    @GetMapping("/list")
    public AjaxResult<TableDataInfo<ReportAssist>> list(ReportAssist reportAssist) {
        List<ReportAssist> list = reportAssistService.selectReportAssistList(reportAssist);
        return getDataTable(list);
    }

    @ApiOperation("查询辅助报表列表(分页)")
    @ApiOperationSupport(order = 2)
    @PreAuthorize("@ss.hasPermi('carbonEmission:assist:list')")
    @GetMapping("/page")
    public AjaxResult<TableDataInfo<ReportAssist>> page(ReportAssist reportAssist) {
        startPage();
        List<ReportAssist> list = reportAssistService.selectReportAssistList(reportAssist);
        return getDataTable(list);
    }

    @ApiOperation("获取辅助报表详细信息")
    @ApiOperationSupport(order = 3)
    @PreAuthorize("@ss.hasPermi('carbonEmission:assist:query')")
    @GetMapping("/get/{id}")
    public AjaxResult<ReportAssist> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(reportAssistService.selectReportAssistById(id));
    }

    @ApiOperation("新增辅助报表")
    @ApiOperationSupport(order = 4)
    @PreAuthorize("@ss.hasPermi('carbonEmission:assist:add')")
    @Log(title = "辅助报表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ReportAssist reportAssist) {
        return toAjax(reportAssistService.insertReportAssist(reportAssist));
    }

    @ApiOperation("修改辅助报表")
    @ApiOperationSupport(order = 5)
    @PreAuthorize("@ss.hasPermi('carbonEmission:assist:edit')")
    @Log(title = "辅助报表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ReportAssist reportAssist) {
        return toAjax(reportAssistService.updateReportAssist(reportAssist));
    }

    @ApiOperation("修改辅助报表")
    @ApiOperationSupport(order = 5)
    @PreAuthorize("@ss.hasPermi('carbonEmission:assist:edit')")
    @Log(title = "辅助报表", businessType = BusinessType.UPDATE)
    @PostMapping("/editList")
    public AjaxResult editList(@RequestBody List<ReportAssist> reportAssistList) {
        return toAjax(reportAssistService.updateReportAssistList(reportAssistList));
    }

    @ApiOperation("删除辅助报表")
    @ApiOperationSupport(order = 6)
    @PreAuthorize("@ss.hasPermi('carbonEmission:assist:remove')")
    @Log(title = "辅助报表", businessType = BusinessType.DELETE)
	@PostMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(reportAssistService.deleteReportAssistByIds(ids));
    }

    @ApiOperation("查询导出点位文件名列表")
    @ApiOperationSupport(order = 7)
    @GetMapping("/getExportHisDataList/{pageSize}/{pageNum}")
    public AjaxResult getExportHisDataList(@PathVariable("pageSize")int pageSize,@PathVariable("pageNum")int pageNum) {
        List<FilenameDTO> list = reportAssistService.getExportHisDataList();
        int start = (pageNum - 1) * pageSize;
        int end = Math.min(start + pageSize, list.size());
        TableDataInfo rspData = new TableDataInfo();
        rspData.setRows(list.subList(start, end));
        rspData.setTotal(new PageInfo(list).getTotal());
        return AjaxResult.success(rspData);
    }
    @ApiOperation("删除导出点位文件名列表")
    @ApiOperationSupport(order = 9)
    @Log(title = "删除导出点位文件名列表", businessType = BusinessType.DELETE)
    @PostMapping("/delExportHisData/{names}")
    public AjaxResult delExportHisData(@PathVariable String[] names) {
        return toAjax(reportAssistService.delExportHisData(names));
    }

}
